import java.nio.file.*;
import java.io.*;
public class HotswapClassLoader extends ClassLoader{
    @Override
    public Class<?> findClass(String name) throws ClassNotFoundException{
        if (name.equals("MonitorImpl")) {
            byte[] b = readClassFromFile("./class/MonitorImpl.class");
            return defineClass(null, b, 0, b.length);
        }
        return super.findClass(name);
    }

    private byte[] readClassFromFile(String name) {
        try {
            return Files.readAllBytes(Path.of(name));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
